/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * edit_recipe.java
 *
 * Created on 08 20, 11, 11:49:45 PM
 */
package introse1;

/**
 *
 * @author rootbeer
 */
public class edit_recipe extends javax.swing.JFrame {

    /** Creates new form edit_recipe */
    public edit_recipe(){
        initComponents();
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }
    public edit_recipe(edit_menu ed, String r) {
        initComponents();          
        edmenu = ed;
        str = r;
        varlist = edmenu.getVars();
        //System.out.println(varlist.getIngredient_name());
        ingredientname.setText(varlist.getIngredient_name());
        edmenu.setVisible(false);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ErrorMessage = new javax.swing.JLabel();
        AddRecipeButton = new javax.swing.JButton();
        BackButton = new javax.swing.JButton();
        UnitOfMeasure = new javax.swing.JTextField();
        Quantity = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        ingredientname = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        AddRecipeButton.setFont(new java.awt.Font("Rockwell", 0, 18));
        AddRecipeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/introse1/addtorecipe.png"))); // NOI18N
        AddRecipeButton.setBorder(null);
        AddRecipeButton.setBorderPainted(false);
        AddRecipeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddRecipeButtonActionPerformed(evt);
            }
        });

        BackButton.setFont(new java.awt.Font("Rockwell", 0, 18));
        BackButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/introse1/back.png"))); // NOI18N
        BackButton.setBorder(null);
        BackButton.setBorderPainted(false);
        BackButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BackButtonActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Rockwell", 0, 24));
        jLabel1.setText("Edit Recipe");

        jLabel2.setFont(new java.awt.Font("Rockwell", 0, 18));
        jLabel2.setText("Unit of Measure: ");

        jLabel3.setFont(new java.awt.Font("Rockwell", 0, 18));
        jLabel3.setText("     Quantity:");

        ingredientname.setText("jLabel4");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel1)
                        .addGap(27, 27, 27)
                        .addComponent(ingredientname, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(Quantity, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                            .addComponent(UnitOfMeasure, javax.swing.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(AddRecipeButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(BackButton))
                    .addComponent(ErrorMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 376, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(ingredientname))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(ErrorMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(UnitOfMeasure, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(Quantity, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(AddRecipeButton)
                    .addComponent(BackButton))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void AddRecipeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddRecipeButtonActionPerformed
        ErrorMessage.setText("");
        if(!UnitOfMeasure.getText().isEmpty()){
            varlist.setUnit_of_measure(UnitOfMeasure.getText());
            try{
                varlist.setRecipe_quantity(Float.parseFloat(Quantity.getText()));
            }catch(NumberFormatException e){
                ErrorMessage.setText("Error value is not a number");
            }
            if(ErrorMessage.getText().isEmpty()){
                this.setVisible(false);
                edmenu.setVars(varlist);
                edmenu.setRecipeTable();
                edmenu.setVisible(true);
            }
        } else{
            ErrorMessage.setText("Error Missing Unit Measure");
        }
}//GEN-LAST:event_AddRecipeButtonActionPerformed

    private void BackButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BackButtonActionPerformed
        this.setVisible(false);
        edmenu.setVisible(true);
}//GEN-LAST:event_BackButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new edit_recipe().setVisible(true);
            }
        });
    }
    public static VariableList varlist;
    public static String str;
    public static edit_menu edmenu;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AddRecipeButton;
    private javax.swing.JButton BackButton;
    private javax.swing.JLabel ErrorMessage;
    private javax.swing.JTextField Quantity;
    private javax.swing.JTextField UnitOfMeasure;
    private javax.swing.JLabel ingredientname;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration//GEN-END:variables
}
